package org.onvivals.admin.module.pms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.onvivals.common.param.PageParam;
import org.onvivals.common.web.PageResult;
import org.onvivals.common.web.Result;
import org.onvivals.module.pms.entity.PmsSttConfig;
import org.onvivals.module.pms.param.PmsSttConfigParam;
import org.onvivals.module.pms.service.IPmsSttConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "语音识别管理")
@RestController
@RequestMapping("/pms/asr")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PmsSttConfigController {

    private final IPmsSttConfigService pmsSttConfigService;

    @Operation(summary = "分页查询全部语音识别")
    @GetMapping("/page")
    public Result<PageResult<PmsSttConfig>> page(PmsSttConfigParam param) {
        PageParam<PmsSttConfig, PmsSttConfigParam> page = new PageParam<>(param);
        IPage<PmsSttConfig> pa = pmsSttConfigService.page(page, page.getWrapper());
        PageResult<PmsSttConfig> pageResult = new PageResult<>(pa.getRecords(), pa.getTotal());
        return Result.OK("查询成功", pageResult);
    }

    @Operation(summary = "查询全部语音识别")
    @GetMapping()
    public Result<List<PmsSttConfig>> list(PmsSttConfigParam param) {
        PageParam<PmsSttConfig, PmsSttConfigParam> page = new PageParam<>(param);
        List<PmsSttConfig> pmsLlmConfigList = pmsSttConfigService.list(page.getOrderWrapper());
        return Result.OK("查询成功", pmsLlmConfigList);
    }

    @Operation(summary = "根据id查询语音识别")
    @GetMapping("/{id}")
    public Result<PmsSttConfig> get(@PathVariable("id") Long id) {
        PmsSttConfig pmsSttConfig = pmsSttConfigService.getById(id);
        return Result.OK("查询成功", pmsSttConfig);
    }

    @Operation(summary = "添加语音识别")
    @PostMapping()
    public Result<?> save(@RequestBody PmsSttConfig pmsSttConfig) {
        if (pmsSttConfigService.save(pmsSttConfig)) {
            return Result.OK("添加成功");
        }
        return Result.error("添加失败");
    }

    @Operation(summary = "修改语音识别")
    @PutMapping()
    public Result<?> update(@RequestBody PmsSttConfig pmsSttConfig) {
        if (pmsSttConfigService.updateById(pmsSttConfig)) {
            return Result.OK("修改成功");
        }
        return Result.error("修改失败");
    }

    @Operation(summary = "删除语音识别")
    @DeleteMapping("/{id}")
    public Result<?> remove(@PathVariable("id") Long id) {
        if (pmsSttConfigService.removeById(id)) {
            return Result.OK("删除成功");
        }
        return Result.error("删除失败");
    }

}
